
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __EEPROM_H
#define __EEPROM_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f37x.h"

/* Exported constants --------------------------------------------------------*/
/* Define the STM32F3xx Flash page size depending on the used STM32 device */
#define PAGE_SIZE  (uint16_t)0x800  /* Page size = 2KByte */

/* EEPROM start address in Flash */
/* 0x0803F000(Page 126), 0x0803F800(Page 127) */
#define EEPROM_START_ADDRESS    ((uint32_t)0x0803F000)

/* Pages 0 and 1 base and end addresses */
#define PAGE0_BASE_ADDRESS      ((uint32_t)(EEPROM_START_ADDRESS + 0x000))
#define PAGE0_END_ADDRESS       ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))

#define PAGE1_BASE_ADDRESS      ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
#define PAGE1_END_ADDRESS       ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))

/* Used Flash pages for EEPROM emulation */
#define PAGE0                   ((uint16_t)0x0000)
#define PAGE1                   ((uint16_t)0x0001)

/* No valid page define */
#define NO_VALID_PAGE           ((uint16_t)0x00AB)

/* Page status definitions */
#define ERASED                  ((uint16_t)0xFFFF)     /* PAGE is empty */
#define RECEIVE_DATA            ((uint16_t)0xEEEE)     /* PAGE is marked to receive data */
#define VALID_PAGE              ((uint16_t)0x0000)     /* PAGE containing valid data */

/* Valid pages in read and write defines */
#define READ_FROM_VALID_PAGE    ((uint8_t)0x00)
#define WRITE_IN_VALID_PAGE     ((uint8_t)0x01)

/* Page full define */
#define PAGE_FULL               ((uint8_t)0x80)

#define	EEPROM_VERSION_INFO		0x0004
/* Exported types ------------------------------------------------------------*/
enum {
	EEPROM_ADDR_START = 0,
	EEPROM_VERSION,

	EEPROM_VOUT1_START=100,
	EEPROM_VOUT1_TOFF_L,	EEPROM_VOUT1_TOFF_H,
	EEPROM_VOUT1_TR1_L,		EEPROM_VOUT1_TR1_H,
	EEPROM_VOUT1_VR1_L,		EEPROM_VOUT1_VR1_H,
	EEPROM_VOUT1_TR2_L,		EEPROM_VOUT1_TR2_H,
	EEPROM_VOUT1_VR2_L,		EEPROM_VOUT1_VR2_H,
	EEPROM_VOUT1_TR3_L,		EEPROM_VOUT1_TR3_H,
	EEPROM_VOUT1_VR3_L,		EEPROM_VOUT1_VR3_H,
	EEPROM_VOUT1_TR4_L,		EEPROM_VOUT1_TR4_H,
	EEPROM_VOUT1_VR4_L,		EEPROM_VOUT1_VR4_H,
	EEPROM_VOUT1_TON_L,		EEPROM_VOUT1_TON_H,
	EEPROM_VOUT1_TF1_L,		EEPROM_VOUT1_TF1_H,
	EEPROM_VOUT1_OFFSET_L,	EEPROM_VOUT1_OFFSET_H,
	EEPROM_VOUT1_RESERVED_L,EEPROM_VOUT1_RESERVED_H,

	EEPROM_VOUT2_START=200,
	EEPROM_VOUT2_TOFF_L,	EEPROM_VOUT2_TOFF_H,
	EEPROM_VOUT2_TR1_L,		EEPROM_VOUT2_TR1_H,
	EEPROM_VOUT2_VR1_L,		EEPROM_VOUT2_VR1_H,
	EEPROM_VOUT2_TR2_L,		EEPROM_VOUT2_TR2_H,
	EEPROM_VOUT2_VR2_L,		EEPROM_VOUT2_VR2_H,
	EEPROM_VOUT2_TR3_L,		EEPROM_VOUT2_TR3_H,
	EEPROM_VOUT2_VR3_L,		EEPROM_VOUT2_VR3_H,
	EEPROM_VOUT2_TR4_L,		EEPROM_VOUT2_TR4_H,
	EEPROM_VOUT2_VR4_L,		EEPROM_VOUT2_VR4_H,
	EEPROM_VOUT2_TON_L,		EEPROM_VOUT2_TON_H,
	EEPROM_VOUT2_TF1_L,		EEPROM_VOUT2_TF1_H,
	EEPROM_VOUT2_OFFSET_L,	EEPROM_VOUT2_OFFSET_H,
	EEPROM_VOUT2_RESERVED_L,EEPROM_VOUT2_RESERVED_H,

	EEPROM_VOUT3_START=300,
	EEPROM_VOUT3_TOFF_L,	EEPROM_VOUT3_TOFF_H,
	EEPROM_VOUT3_TR1_L,		EEPROM_VOUT3_TR1_H,
	EEPROM_VOUT3_VR1_L,		EEPROM_VOUT3_VR1_H,
	EEPROM_VOUT3_TR2_L,		EEPROM_VOUT3_TR2_H,
	EEPROM_VOUT3_VR2_L,		EEPROM_VOUT3_VR2_H,
	EEPROM_VOUT3_TR3_L,		EEPROM_VOUT3_TR3_H,
	EEPROM_VOUT3_VR3_L,		EEPROM_VOUT3_VR3_H,
	EEPROM_VOUT3_TR4_L,		EEPROM_VOUT3_TR4_H,
	EEPROM_VOUT3_VR4_L,		EEPROM_VOUT3_VR4_H,
	EEPROM_VOUT3_TON_L,		EEPROM_VOUT3_TON_H,
	EEPROM_VOUT3_TF1_L,		EEPROM_VOUT3_TF1_H,
	EEPROM_VOUT3_OFFSET_L,	EEPROM_VOUT3_OFFSET_H,
	EEPROM_VOUT3_RESERVED_L,EEPROM_VOUT3_RESERVED_H,

	NB_OF_VAR
};

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
uint16_t EE_Init(void);
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
void EE_ReadVariable32(uint32_t VirtAddress, uint32_t* Data);
void EE_WriteVariable32(uint32_t VirtAddress, uint32_t Data);


#endif /* __EEPROM_H */
